Code
library(readr)
library(dplyr)
library(ggplot2)
library(forcats)library(readr)
library(dplyr)
library(ggplot2)
library(forcats)Fichier > Nouveau projet > Nouveau répertoire > Projet Quarto >ou, dans un projet existant :
Fichier > Nouveau fichier > R Quarto documentBasculer successivement sur l’éditeur texte brut / WYSIWYM1
Tricoter le document
Tricoter le document.
ra <- read_rds("donnees/ra_2020.rds") ra |>
summarise(sau_tot_ha = sum(sau_tot, na.rm = TRUE))# A tibble: 1 × 1
sau_tot_ha
<dbl>
1 64986.
sau_tot_ha <- ra |>
summarise(sau_tot_ha = sum(sau_tot, na.rm = TRUE)) |>
pull(1)La SAU totale vaut 6.498577^{4} ha.
La SAU totale vaut 64 985,8 ha.
options() ou des knitr::knit_hooks() pour ne pas formater chaque sortieoptions(OutDec = ",",
digits = 1,
scipen = 1e3)
# ou par exemple
knitr::knit_hooks$set(inline = function(x) {
if (!is.numeric(x)) {
x
} else {
prettyNum(x, big.mark = " ")
}
})La SAU totale vaut 64 986 ha.
ra# A tibble: 1.000 × 11
siege_code_com siege_lib_com siege_dep siege_lib_dep siege_reg siege_lib_reg
<chr> <chr> <chr> <chr> <chr> <chr>
1 97128 LESCURE D ALB… 51 VENDEE 52 BOURGOGNE FR…
2 37178 MARCOLES 57 PAS DE CALAIS 76 OCCITANIE
3 89436 VALREAS 11 PYRENEES ATL… 53 NOUVELLE AQU…
4 89143 RIOTORD 95 PYRENEES ATL… 53 OCCITANIE
5 97103 CAUMONT 34 HAUTE CORSE 32 AUVERGNE RHO…
6 84087 AZY LE VIF 37 HAUTE SAVOIE 53 NOUVELLE AQU…
7 40317 SOINGS EN SOL… 971 VIENNE 44 NORMANDIE
8 12120 BONNAT 22 AVEYRON 75 AUVERGNE RHO…
9 33389 MONTASTRUC LA… 16 CALVADOS 03 NOUVELLE AQU…
10 28111 OYRE 87 MAINE ET LOI… 76 BOURGOGNE FR…
# ℹ 990 more rows
# ℹ 5 more variables: geo_lct <chr>, pbstot_coef17 <dbl>, otefda_coef17 <chr>,
# sau_tot <dbl>, ugbag_tot <dbl>
library(gt)
ra |>
slice_head(n = 5) |>
gt()| siege_code_com | siege_lib_com | siege_dep | siege_lib_dep | siege_reg | siege_lib_reg | geo_lct | pbstot_coef17 | otefda_coef17 | sau_tot | ugbag_tot |
|---|---|---|---|---|---|---|---|---|---|---|
| 97128 | LESCURE D ALBIGEOIS | 51 | VENDEE | 52 | BOURGOGNE FRANCHE COMTE | FR_CRS3035RES1000mN2888000E3883000 | 2359 | 4600 | 109 | 0 |
| 37178 | MARCOLES | 57 | PAS DE CALAIS | 76 | OCCITANIE | FR_CRS3035RES1000mN2316000E3389000 | 3857 | 4600 | 220 | 0 |
| 89436 | VALREAS | 11 | PYRENEES ATLANTIQUES | 53 | NOUVELLE AQUITAINE | FR_CRS3035RES1000mN2316000E3562000 | 478411 | 6184 | 0 | 167 |
| 89143 | RIOTORD | 95 | PYRENEES ATLANTIQUES | 53 | OCCITANIE | FR_CRS3035RES1000mN2372000E4045000 | 15800 | 6184 | 131 | 0 |
| 97103 | CAUMONT | 34 | HAUTE CORSE | 32 | AUVERGNE RHONE ALPES | FR_CRS3035RES1000mN2540000E3823000 | 213106 | 1516 | 276 | 0 |
library(knitr)
ra |>
slice_head(n = 5) |>
kable()| siege_code_com | siege_lib_com | siege_dep | siege_lib_dep | siege_reg | siege_lib_reg | geo_lct | pbstot_coef17 | otefda_coef17 | sau_tot | ugbag_tot |
|---|---|---|---|---|---|---|---|---|---|---|
| 97128 | LESCURE D ALBIGEOIS | 51 | VENDEE | 52 | BOURGOGNE FRANCHE COMTE | FR_CRS3035RES1000mN2888000E3883000 | 2359 | 4600 | 109 | 0 |
| 37178 | MARCOLES | 57 | PAS DE CALAIS | 76 | OCCITANIE | FR_CRS3035RES1000mN2316000E3389000 | 3857 | 4600 | 220 | 0 |
| 89436 | VALREAS | 11 | PYRENEES ATLANTIQUES | 53 | NOUVELLE AQUITAINE | FR_CRS3035RES1000mN2316000E3562000 | 478411 | 6184 | 0 | 167 |
| 89143 | RIOTORD | 95 | PYRENEES ATLANTIQUES | 53 | OCCITANIE | FR_CRS3035RES1000mN2372000E4045000 | 15800 | 6184 | 131 | 0 |
| 97103 | CAUMONT | 34 | HAUTE CORSE | 32 | AUVERGNE RHONE ALPES | FR_CRS3035RES1000mN2540000E3823000 | 213106 | 1516 | 276 | 0 |
Javascript avec datatable
library(DT)
ra |>
slice_head(n = 100) |>
datatable(
options = list(
language = list(
url = "https://cdn.datatables.net/plug-ins/1.10.11/i18n/French.json")))ra.graph_sau <- ra |>
summarise(.by = c(siege_lib_dep),
sau_dep_ha = sum(sau_tot, na.rm = TRUE),
n = paste(n(), "exploit.")) |>
slice_max(sau_dep_ha, n = 10) |>
mutate(siege_lib_dep = fct_reorder(siege_lib_dep, sau_dep_ha)) |>
ggplot(aes(siege_lib_dep,
sau_dep_ha,
text = n)) +
geom_col() +
coord_flip() +
labs(title = "10 plus grandes SAU",
x = "dép.",
y = "surface (ha)")
graph_saulibrary(plotly)
graph_sau |>
ggplotly(tooltip = "n")Il est possible de choisir l’emprise et l’emplacement des graphiques (disponible aussi pour d’autres éléments).
column:.densite_sau <- ra |>
ggplot() +
geom_density(aes(sau_tot), fill = "darkslategray3")
densite_sauPar exemple : densité ou histogramme de la sau_tot.
layout-ncol:.densite_sau
graph_saulibrary(sf)
library(leaflet)
"~/CERISE/03-Espace-de-Diffusion/000_Referentiels/0040_Geo/IGN/adminexpress/adminexpress_cog_simpl_000_2024.gpkg" |>
read_sf(layer = "region") |>
leaflet() |>
addTiles() |>
addPolygons()Hors CERISE ?
Ce document est produit par :
C:/Users/michael.delorme/Documents/formations/formation_quarto/exercices/exercices_quarto.qmd
Ce projet est versionné dans :
https://github.com/SSM-Agriculture/Formation-R-perf-03-quarto
What You See Is What You Mean↩︎